package argo.hot100.tree;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class InorderTraversal {
    public List<Integer> inorderTraversal(TreeNode root) {

        List<Integer> res = new ArrayList<>();
        Stack<TreeNode> stack = new Stack<>();
        while (!stack.isEmpty() || root != null) {
            while (root != null) {
                stack.push(root);
                root = root.left;
            }
            root = stack.pop();
            res.add(root.val);
            root = root.right;

        }
        return res;
    }




    public List<Integer> inorderTraversalRev(TreeNode root) {

        List<Integer> res = new ArrayList<>();
        inorderTraversalRev(root,res);
        return res;
    }


    public void inorderTraversalRev(TreeNode root, List<Integer> res) {
        if(root==null){
            return;
        }
        inorderTraversalRev(root.left,res);
        res.add(root.val);
        inorderTraversalRev(root.right,res);

    }






    }
